package com.example.demo.util;

import com.alibaba.fastjson.JSONObject;
import com.example.demo.dbo.CmsPublishRespone;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.InputSource;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import java.io.StringReader;

public class Test111322 {

    public static void main(String[] args) {

    String response ="{\"success\":true,\"code\":\"0000\",\"message\":\"succeed\",\"dataRows\":1,\"data\":\"<?xml version=\\\"1.0\\\" encoding=\\\"GBK\\\"?>\\n<returnvalue>\\n\\t<result>success</result>\\n\\t<fileid>-1</fileid>\\n\\t<errormessage>org.springframework.dao.DuplicateKeyException: \\n### Error updating database.  Cause: java.sql.SQLIntegrityConstraintViolationException: Duplicate entry '40490236' for key 'content_28.PRIMARY'\\n### The error may exist in cn/people/mapper/microcms/ContentMapper.java (best guess)\\n### The error may involve cn.people.mapper.microcms.ContentMapper.insert-Inline\\n### The error occurred while setting parameters\\n### SQL: INSERT INTO content  ( CONTENT_ID, TITLE, PRETITLE, SUBTITLE, CONTENT, AUTHOR, SUMMARY, LANGUAGE_ID, INPUT_BY, INPUT_DATE,  ORIGIN_ID, DISPLAY_DATE, MEDIA_COUNT, STATUS, DELETED, NODE_ID, TEMPLATE_ID, EDITOR,       INPUT_MODE,     CONTENT_MARK,  SIZE )  VALUES  ( ?, ?, ?, ?, ?, ?, ?, ?, ?, ?,  ?, ?, ?, ?, ?, ?, ?, ?,       ?,     ?,  ? )\\n### Cause: java.sql.SQLIntegrityConstraintViolationException: Duplicate entry '40490236' for key 'content_28.PRIMARY'\\n; Duplicate entry '40490236' for key 'content_28.PRIMARY'; nested exception is java.sql.SQLIntegrityConstraintViolationException: Duplicate entry '40490236' for key 'content_28.PRIMARY'\\norg.springframework.dao.DuplicateKeyException: \\n### Error updating database.  Cause: java.sql.SQLIntegrityConstraintViolationException: Duplicate entry '40490236' for key 'content_28.PRIMARY'\\n### The error may exist in cn/people/mapper/microcms/ContentMapper.java (best guess)\\n### The error may involve cn.people.mapper.microcms.ContentMapper.insert-Inline\\n### The error occurred while setting parameters\\n### SQL: INSERT INTO content  ( CONTENT_ID, TITLE, PRETITLE, SUBTITLE, CONTENT, AUTHOR, SUMMARY, LANGUAGE_ID, INPUT_BY, INPUT_DATE,  ORIGIN_ID, DISPLAY_DATE, MEDIA_COUNT, STATUS, DELETED, NODE_ID, TEMPLATE_ID, EDITOR,       INPUT_MODE,     CONTENT_MARK,  SIZE )  VALUES  ( ?, ?, ?, ?, ?, ?, ?, ?, ?, ?,  ?, ?, ?, ?, ?, ?, ?, ?,       ?,     ?,  ? )\\n### Cause: java.sql.SQLIntegrityConstraintViolationException: Duplicate entry '40490236' for key 'content_28.PRIMARY'\\n; Duplicate entry '40490236' for key 'content_28.PRIMARY'; nested exception is java.sql.SQLIntegrityConstraintViolationException: Duplicate entry '40490236' for key 'content_28.PRIMARY'\\n\\tat org.springframework.jdbc.support.SQLErrorCodeSQLExceptionTranslator.doTranslate(SQLErrorCodeSQLExceptionTranslator.java:247)\\n\\tat org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:72)\\n\\tat org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:88)\\n\\tat org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:440)\\n\\tat com.sun.proxy.$Proxy133.insert(Unknown Source)\\n\\tat org.mybatis.spring.SqlSessionTemplate.insert(SqlSessionTemplate.java:271)\\n\\tat com.baomidou.mybatisplus.core.override.MybatisMapperMethod.execute(MybatisMapperMethod.java:60)\\n\\tat com.baomidou.mybatisplus.core.override.MybatisMapperProxy$PlainMethodInvoker.invoke(MybatisMapperProxy.java:148)\\n\\tat com.baomidou.mybatisplus.core.override.MybatisMapperProxy.invoke(MybatisMapperProxy.java:89)\\n\\tat com.sun.proxy.$Proxy164.insert(Unknown Source)\\n\\tat cn.people.service.local.impl.editor.ContentServiceImpl.insert(ContentServiceImpl.java:475)\\n\\tat cn.people.service.local.impl.editor.ContentServiceImpl$$FastClassBySpringCGLIB$$907ad1a7.invoke(<generated>)\\n\\tat org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:218)\\n\\tat org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:779)\\n\\tat org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163)\\n\\tat org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:750)\\n\\tat com.alibaba.druid.support.spring.stat.DruidStatInterceptor.invoke(DruidStatInterceptor.java:73)\\n\\tat org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)\\n\\tat org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:750)\\n\\tat org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:692)\\n\\tat cn.people.service.local.impl.editor.ContentServiceImpl$$EnhancerBySpringCGLIB$$3c39df4f.insert(<generated>)\\n\\tat jdk.internal.reflect.GeneratedMethodAccessor1002.invoke(Unknown Source)\\n\\tat java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)\\n\\tat java.base/java.lang.reflect.Method.invoke(Method.java:566)\\n\\tat org.springframework.util.ReflectionUtils.invokeMethod(ReflectionUtils.java:282)\\n\\tat org.springframework.cloud.context.scope.GenericScope$LockedScopedProxyFactoryBean.invoke(GenericScope.java:499)\\n\\tat org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)\\n\\tat org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:750)\\n\\tat org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:692)\\n\\tat cn.people.service.local.impl.editor.ContentServiceImpl$$EnhancerBySpringCGLIB$$c801b3a8.insert(<generated>)\\n\\tat cn.people.service.dubbo.editor.ContentDubboServiceImpl.insert(ContentDubboServiceImpl.java:141)\\n\\tat org.apache.dubbo.common.bytecode.Wrapper3.invokeMethod(Wrapper3.java)\\n\\tat org.apache.dubbo.rpc.proxy.javassist.JavassistProxyFactory$1.doInvoke(JavassistProxyFactory.java:47)\\n\\tat org.apache.dubbo.rpc.proxy.AbstractProxyInvoker.invoke(AbstractProxyInvoker.java:84)\\n\\tat org.apache.dubbo.config.invoker.DelegateProviderMetaDataInvoker.invoke(DelegateProviderMetaDataInvoker.java:56)\\n\\tat org.apache.dubbo.rpc.protocol.InvokerWrapper.invoke(InvokerWrapper.java:56)\\n\\tat cn.people.service.dubbo.filter.ServerTraceFilter.invoke(ServerTraceFilter.java:55)\\n\\tat org.apache.dubbo.rpc.protocol.FilterNode.invoke(FilterNode.java:61)\\n\\tat org.apache.dubbo.rpc.protocol.dubbo.filter.TraceFilter.invoke(TraceFilter.java:77)\\n\\tat org.apache.dubbo.rpc.protocol.FilterNode.invoke(FilterNode.java:61)\\n\\tat org.apache.dubbo.rpc.filter.TimeoutFilter.invoke(TimeoutFilter.java:44)\\n\\tat org.apache.dubbo.rpc.protocol.FilterNode.invoke(FilterNode.java:61)\\n\\tat org.apache.dubbo.monitor.support.MonitorFilter.invoke(MonitorFilter.java:91)\\n\\tat org.apache.dubbo.rpc.protocol.FilterNode.invoke(FilterNode.java:61)\\n\\tat org.apache.dubbo.rpc.filter.ExceptionFilter.invoke(ExceptionFilter.java:52)\\n\\tat org.apache.dubbo.rpc.protocol.FilterNode.invoke(FilterNode.java:61)\\n\\tat org.apache.dubbo.rpc.filter.GenericFilter.invoke(GenericFilter.java:192)\\n\\tat org.apache.dubbo.rpc.protocol.FilterNode.invoke(FilterNode.java:61)\\n\\tat org.apache.dubbo.rpc.filter.ClassLoaderFilter.invoke(ClassLoaderFilter.java:38)\\n\\tat org.apache.dubbo.rpc.protocol.FilterNode.invoke(FilterNode.java:61)\\n\\tat org.apache.dubbo.rpc.filter.EchoFilter.invoke(EchoFilter.java:41)\\n\\tat org.apache.dubbo.rpc.protocol.FilterNode.invoke(FilterNode.java:61)\\n\\tat org.apache.dubbo.rpc.filter.ContextFilter.invoke(ContextFilter.java:129)\\n\\tat org.apache.dubbo.rpc.protocol.FilterNode.invoke(FilterNode.java:61)\\n\\tat org.apache.dubbo.rpc.protocol.dubbo.DubboProtocol$1.reply(DubboProtocol.java:148)\\n\\tat org.apache.dubbo.remoting.exchange.support.header.HeaderExchangeHandler.handleRequest(HeaderExchangeHandler.java:100)\\n\\tat org.apache.dubbo.remoting.exchange.support.header.HeaderExchangeHandler.received(HeaderExchangeHandler.java:175)\\n\\tat org.apache.dubbo.remoting.transport.DecodeHandler.received(DecodeHandler.java:51)\\n\\tat org.apache.dubbo.remoting.transport.dispatcher.ChannelEventRunnable.run(ChannelEventRunnable.java:57)\\n\\tat java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)\\n\\tat java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)\\n\\tat org.apache.dubbo.common.threadlocal.InternalRunnable.run(InternalRunnable.java:41)\\n\\tat java.base/java.lang.Thread.run(Thread.java:834)\\nCaused by: java.sql.SQLIntegrityConstraintViolationException: Duplicate entry '40490236' for key 'content_28.PRIMARY'\\n\\tat com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:117)\\n\\tat com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:122)\\n\\tat com.mysql.cj.jdbc.ClientPreparedStatement.executeInternal(ClientPreparedStatement.java:953)\\n\\tat com.mysql.cj.jdbc.ClientPreparedStatement.execute(ClientPreparedStatement.java:371)\\n\\tat com.alibaba.druid.filter.FilterChainImpl.preparedStatement_execute(FilterChainImpl.java:3461)\\n\\tat com.alibaba.druid.wall.WallFilter.preparedStatement_execute(WallFilter.java:663)\\n\\tat com.alibaba.druid.filter.FilterChainImpl.preparedStatement_execute(FilterChainImpl.java:3459)\\n\\tat com.alibaba.druid.filter.FilterEventAdapter.preparedStatement_execute(FilterEventAdapter.java:440)\\n\\tat com.alibaba.druid.filter.FilterChainImpl.preparedStatement_execute(FilterChainImpl.java:3459)\\n\\tat com.alibaba.druid.filter.FilterAdapter.preparedStatement_execute(FilterAdapter.java:1081)\\n\\tat com.alibaba.druid.filter.FilterChainImpl.preparedStatement_execute(FilterChainImpl.java:3459)\\n\\tat com.alibaba.druid.proxy.jdbc.PreparedStatementProxyImpl.execute(PreparedStatementProxyImpl.java:167)\\n\\tat com.alibaba.druid.pool.DruidPooledPreparedStatement.execute(DruidPooledPreparedStatement.java:497)\\n\\tat org.apache.ibatis.executor.statement.PreparedStatementHandler.update(PreparedStatementHandler.java:47)\\n\\tat org.apache.ibatis.executor.statement.RoutingStatementHandler.update(RoutingStatementHandler.java:74)\\n\\tat com.baomidou.mybatisplus.core.executor.MybatisSimpleExecutor.doUpdate(MybatisSimpleExecutor.java:56)\\n\\tat org.apache.ibatis.executor.BaseExecutor.update(BaseExecutor.java:117)\\n\\tat com.baomidou.mybatisplus.core.executor.MybatisCachingExecutor.update(MybatisCachingExecutor.java:85)\\n\\tat jdk.internal.reflect.GeneratedMethodAccessor587.invoke(Unknown Source)\\n\\tat java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)\\n\\tat java.base/java.lang.reflect.Method.invoke(Method.java:566)\\n\\tat org.apache.ibatis.plugin.Invocation.proceed(Invocation.java:49)\\n\\tat cn.people.config.mybatis.MybatisInterceptor.intercept(MybatisInterceptor.java:64)\\n\\tat org.apache.ibatis.plugin.Plugin.invoke(Plugin.java:61)\\n\\tat com.sun.proxy.$Proxy269.update(Unknown Source)\\n\\tat jdk.internal.reflect.GeneratedMethodAccessor587.invoke(Unknown Source)\\n\\tat java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)\\n\\tat java.base/java.lang.reflect.Method.invoke(Method.java:566)\\n\\tat org.apache.ibatis.plugin.Plugin.invoke(Plugin.java:63)\\n\\tat com.sun.proxy.$Proxy269.update(Unknown Source)\\n\\tat org.apache.ibatis.session.defaults.DefaultSqlSession.update(DefaultSqlSession.java:197)\\n\\tat org.apache.ibatis.session.defaults.DefaultSqlSession.insert(DefaultSqlSession.java:184)\\n\\tat jdk.internal.reflect.GeneratedMethodAccessor694.invoke(Unknown Source)\\n\\tat java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)\\n\\tat java.base/java.lang.reflect.Method.invoke(Method.java:566)\\n\\tat org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:426)\\n\\t... 59 more\\n  失败</errormessage>\\n</returnvalue>\\n\",\"serverIp\":\"10.10.11.120\",\"timestamp\":\"2025-07-03 17:14:49.922\"}";
//    response = "{\"success\":true,\"code\":\"0000\",\"message\":\"succeed\",\"dataRows\":1,\"data\":\"<?xml version=\\\"1.0\\\" encoding=\\\"GBK\\\"?>\\n<returnvalue>\\n\\t<result>success</result>\\n\\t<fileid>40497991</fileid>\\n\\t<errormessage>org.springframework.dao.DuplicateKeyException: \\n### Error updating database.  Cause: java.sql.SQLIntegrityConstraintViolationException: Duplicate entry '40490236' for key 'content_28.PRIMARY'\\n### The error may exist in cn/people/mapper/microcms/ContentMapper.java (best guess)\\n### The error may involve cn.people.mapper.microcms.ContentMapper.insert-Inline\\n### The error occurred while setting parameters\\n### SQL: INSERT INTO content  ( CONTENT_ID, TITLE, PRETITLE, SUBTITLE, CONTENT, AUTHOR, SUMMARY, LANGUAGE_ID, INPUT_BY, INPUT_DATE,  ORIGIN_ID, DISPLAY_DATE, MEDIA_COUNT, STATUS, DELETED, NODE_ID, TEMPLATE_ID, EDITOR,       INPUT_MODE,     CONTENT_MARK,  SIZE )  VALUES  ( ?, ?, ?, ?, ?, ?, ?, ?, ?, ?,  ?, ?, ?, ?, ?, ?, ?, ?,       ?,     ?,  ? )\\n### Cause: java.sql.SQLIntegrityConstraintViolationException: Duplicate entry '40490236' for key 'content_28.PRIMARY'\\n; Duplicate entry '40490236' for key 'content_28.PRIMARY'; nested exception is java.sql.SQLIntegrityConstraintViolationException: Duplicate entry '40490236' for key 'content_28.PRIMARY'\\norg.springframework.dao.DuplicateKeyException: \\n### Error updating database.  Cause: java.sql.SQLIntegrityConstraintViolationException: Duplicate entry '40490236' for key 'content_28.PRIMARY'\\n### The error may exist in cn/people/mapper/microcms/ContentMapper.java (best guess)\\n### The error may involve cn.people.mapper.microcms.ContentMapper.insert-Inline\\n### The error occurred while setting parameters\\n### SQL: INSERT INTO content  ( CONTENT_ID, TITLE, PRETITLE, SUBTITLE, CONTENT, AUTHOR, SUMMARY, LANGUAGE_ID, INPUT_BY, INPUT_DATE,  ORIGIN_ID, DISPLAY_DATE, MEDIA_COUNT, STATUS, DELETED, NODE_ID, TEMPLATE_ID, EDITOR,       INPUT_MODE,     CONTENT_MARK,  SIZE )  VALUES  ( ?, ?, ?, ?, ?, ?, ?, ?, ?, ?,  ?, ?, ?, ?, ?, ?, ?, ?,       ?,     ?,  ? )\\n### Cause: java.sql.SQLIntegrityConstraintViolationException: Duplicate entry '40490236' for key 'content_28.PRIMARY'\\n; Duplicate entry '40490236' for key 'content_28.PRIMARY'; nested exception is java.sql.SQLIntegrityConstraintViolationException: Duplicate entry '40490236' for key 'content_28.PRIMARY'\\n\\tat org.springframework.jdbc.support.SQLErrorCodeSQLExceptionTranslator.doTranslate(SQLErrorCodeSQLExceptionTranslator.java:247)\\n\\tat org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:72)\\n\\tat org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:88)\\n\\tat org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:440)\\n\\tat com.sun.proxy.$Proxy133.insert(Unknown Source)\\n\\tat org.mybatis.spring.SqlSessionTemplate.insert(SqlSessionTemplate.java:271)\\n\\tat com.baomidou.mybatisplus.core.override.MybatisMapperMethod.execute(MybatisMapperMethod.java:60)\\n\\tat com.baomidou.mybatisplus.core.override.MybatisMapperProxy$PlainMethodInvoker.invoke(MybatisMapperProxy.java:148)\\n\\tat com.baomidou.mybatisplus.core.override.MybatisMapperProxy.invoke(MybatisMapperProxy.java:89)\\n\\tat com.sun.proxy.$Proxy164.insert(Unknown Source)\\n\\tat cn.people.service.local.impl.editor.ContentServiceImpl.insert(ContentServiceImpl.java:475)\\n\\tat cn.people.service.local.impl.editor.ContentServiceImpl$$FastClassBySpringCGLIB$$907ad1a7.invoke(<generated>)\\n\\tat org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:218)\\n\\tat org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:779)\\n\\tat org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163)\\n\\tat org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:750)\\n\\tat com.alibaba.druid.support.spring.stat.DruidStatInterceptor.invoke(DruidStatInterceptor.java:73)\\n\\tat org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)\\n\\tat org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:750)\\n\\tat org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:692)\\n\\tat cn.people.service.local.impl.editor.ContentServiceImpl$$EnhancerBySpringCGLIB$$3c39df4f.insert(<generated>)\\n\\tat jdk.internal.reflect.GeneratedMethodAccessor1002.invoke(Unknown Source)\\n\\tat java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)\\n\\tat java.base/java.lang.reflect.Method.invoke(Method.java:566)\\n\\tat org.springframework.util.ReflectionUtils.invokeMethod(ReflectionUtils.java:282)\\n\\tat org.springframework.cloud.context.scope.GenericScope$LockedScopedProxyFactoryBean.invoke(GenericScope.java:499)\\n\\tat org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)\\n\\tat org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:750)\\n\\tat org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:692)\\n\\tat cn.people.service.local.impl.editor.ContentServiceImpl$$EnhancerBySpringCGLIB$$c801b3a8.insert(<generated>)\\n\\tat cn.people.service.dubbo.editor.ContentDubboServiceImpl.insert(ContentDubboServiceImpl.java:141)\\n\\tat org.apache.dubbo.common.bytecode.Wrapper3.invokeMethod(Wrapper3.java)\\n\\tat org.apache.dubbo.rpc.proxy.javassist.JavassistProxyFactory$1.doInvoke(JavassistProxyFactory.java:47)\\n\\tat org.apache.dubbo.rpc.proxy.AbstractProxyInvoker.invoke(AbstractProxyInvoker.java:84)\\n\\tat org.apache.dubbo.config.invoker.DelegateProviderMetaDataInvoker.invoke(DelegateProviderMetaDataInvoker.java:56)\\n\\tat org.apache.dubbo.rpc.protocol.InvokerWrapper.invoke(InvokerWrapper.java:56)\\n\\tat cn.people.service.dubbo.filter.ServerTraceFilter.invoke(ServerTraceFilter.java:55)\\n\\tat org.apache.dubbo.rpc.protocol.FilterNode.invoke(FilterNode.java:61)\\n\\tat org.apache.dubbo.rpc.protocol.dubbo.filter.TraceFilter.invoke(TraceFilter.java:77)\\n\\tat org.apache.dubbo.rpc.protocol.FilterNode.invoke(FilterNode.java:61)\\n\\tat org.apache.dubbo.rpc.filter.TimeoutFilter.invoke(TimeoutFilter.java:44)\\n\\tat org.apache.dubbo.rpc.protocol.FilterNode.invoke(FilterNode.java:61)\\n\\tat org.apache.dubbo.monitor.support.MonitorFilter.invoke(MonitorFilter.java:91)\\n\\tat org.apache.dubbo.rpc.protocol.FilterNode.invoke(FilterNode.java:61)\\n\\tat org.apache.dubbo.rpc.filter.ExceptionFilter.invoke(ExceptionFilter.java:52)\\n\\tat org.apache.dubbo.rpc.protocol.FilterNode.invoke(FilterNode.java:61)\\n\\tat org.apache.dubbo.rpc.filter.GenericFilter.invoke(GenericFilter.java:192)\\n\\tat org.apache.dubbo.rpc.protocol.FilterNode.invoke(FilterNode.java:61)\\n\\tat org.apache.dubbo.rpc.filter.ClassLoaderFilter.invoke(ClassLoaderFilter.java:38)\\n\\tat org.apache.dubbo.rpc.protocol.FilterNode.invoke(FilterNode.java:61)\\n\\tat org.apache.dubbo.rpc.filter.EchoFilter.invoke(EchoFilter.java:41)\\n\\tat org.apache.dubbo.rpc.protocol.FilterNode.invoke(FilterNode.java:61)\\n\\tat org.apache.dubbo.rpc.filter.ContextFilter.invoke(ContextFilter.java:129)\\n\\tat org.apache.dubbo.rpc.protocol.FilterNode.invoke(FilterNode.java:61)\\n\\tat org.apache.dubbo.rpc.protocol.dubbo.DubboProtocol$1.reply(DubboProtocol.java:148)\\n\\tat org.apache.dubbo.remoting.exchange.support.header.HeaderExchangeHandler.handleRequest(HeaderExchangeHandler.java:100)\\n\\tat org.apache.dubbo.remoting.exchange.support.header.HeaderExchangeHandler.received(HeaderExchangeHandler.java:175)\\n\\tat org.apache.dubbo.remoting.transport.DecodeHandler.received(DecodeHandler.java:51)\\n\\tat org.apache.dubbo.remoting.transport.dispatcher.ChannelEventRunnable.run(ChannelEventRunnable.java:57)\\n\\tat java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)\\n\\tat java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)\\n\\tat org.apache.dubbo.common.threadlocal.InternalRunnable.run(InternalRunnable.java:41)\\n\\tat java.base/java.lang.Thread.run(Thread.java:834)\\nCaused by: java.sql.SQLIntegrityConstraintViolationException: Duplicate entry '40490236' for key 'content_28.PRIMARY'\\n\\tat com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:117)\\n\\tat com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:122)\\n\\tat com.mysql.cj.jdbc.ClientPreparedStatement.executeInternal(ClientPreparedStatement.java:953)\\n\\tat com.mysql.cj.jdbc.ClientPreparedStatement.execute(ClientPreparedStatement.java:371)\\n\\tat com.alibaba.druid.filter.FilterChainImpl.preparedStatement_execute(FilterChainImpl.java:3461)\\n\\tat com.alibaba.druid.wall.WallFilter.preparedStatement_execute(WallFilter.java:663)\\n\\tat com.alibaba.druid.filter.FilterChainImpl.preparedStatement_execute(FilterChainImpl.java:3459)\\n\\tat com.alibaba.druid.filter.FilterEventAdapter.preparedStatement_execute(FilterEventAdapter.java:440)\\n\\tat com.alibaba.druid.filter.FilterChainImpl.preparedStatement_execute(FilterChainImpl.java:3459)\\n\\tat com.alibaba.druid.filter.FilterAdapter.preparedStatement_execute(FilterAdapter.java:1081)\\n\\tat com.alibaba.druid.filter.FilterChainImpl.preparedStatement_execute(FilterChainImpl.java:3459)\\n\\tat com.alibaba.druid.proxy.jdbc.PreparedStatementProxyImpl.execute(PreparedStatementProxyImpl.java:167)\\n\\tat com.alibaba.druid.pool.DruidPooledPreparedStatement.execute(DruidPooledPreparedStatement.java:497)\\n\\tat org.apache.ibatis.executor.statement.PreparedStatementHandler.update(PreparedStatementHandler.java:47)\\n\\tat org.apache.ibatis.executor.statement.RoutingStatementHandler.update(RoutingStatementHandler.java:74)\\n\\tat com.baomidou.mybatisplus.core.executor.MybatisSimpleExecutor.doUpdate(MybatisSimpleExecutor.java:56)\\n\\tat org.apache.ibatis.executor.BaseExecutor.update(BaseExecutor.java:117)\\n\\tat com.baomidou.mybatisplus.core.executor.MybatisCachingExecutor.update(MybatisCachingExecutor.java:85)\\n\\tat jdk.internal.reflect.GeneratedMethodAccessor587.invoke(Unknown Source)\\n\\tat java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)\\n\\tat java.base/java.lang.reflect.Method.invoke(Method.java:566)\\n\\tat org.apache.ibatis.plugin.Invocation.proceed(Invocation.java:49)\\n\\tat cn.people.config.mybatis.MybatisInterceptor.intercept(MybatisInterceptor.java:64)\\n\\tat org.apache.ibatis.plugin.Plugin.invoke(Plugin.java:61)\\n\\tat com.sun.proxy.$Proxy269.update(Unknown Source)\\n\\tat jdk.internal.reflect.GeneratedMethodAccessor587.invoke(Unknown Source)\\n\\tat java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)\\n\\tat java.base/java.lang.reflect.Method.invoke(Method.java:566)\\n\\tat org.apache.ibatis.plugin.Plugin.invoke(Plugin.java:63)\\n\\tat com.sun.proxy.$Proxy269.update(Unknown Source)\\n\\tat org.apache.ibatis.session.defaults.DefaultSqlSession.update(DefaultSqlSession.java:197)\\n\\tat org.apache.ibatis.session.defaults.DefaultSqlSession.insert(DefaultSqlSession.java:184)\\n\\tat jdk.internal.reflect.GeneratedMethodAccessor694.invoke(Unknown Source)\\n\\tat java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)\\n\\tat java.base/java.lang.reflect.Method.invoke(Method.java:566)\\n\\tat org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:426)\\n\\t... 59 more\\n  失败</errormessage>\\n\\t<url>http://v.people.cn/n1/2025/0610/c61600-40497991.html</url>\\n</returnvalue>\\n\",\"serverIp\":\"10.6.224.58\",\"timestamp\":\"2025-06-10 21:13:43.185\"}";
        response = response.replaceAll("<generated>", "").replaceAll("</generated>", "");
        CmsPublishRespone cmsPublishRespone = JsonUtil.fromJson(response, CmsPublishRespone.class);

        String[] strings = parseXml(cmsPublishRespone.getData());
//        String fileid = strings[0];
//        String result = strings[1];
        String errormessage = strings[2];
//        System.out.println(errormessage);

        String errorMessage = "1111112222";
        System.out.println();
        String substring = errorMessage.substring(0, Math.min(4, errorMessage.length()));
        System.out.println(substring);

//        System.out.println(parseErrorMessage(response));
    }

    public static String[] parseXml(String xmlData) {
        String fileid = "";
        String result = "";
        String errormessage = "";

        try {
            DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
            DocumentBuilder builder = factory.newDocumentBuilder();
            Document document = builder.parse(new java.io.ByteArrayInputStream(xmlData.getBytes("GBK")));

            // 获取根元素
            Element root = document.getDocumentElement();

            // 解析 <result> 元素
            NodeList resultList = root.getElementsByTagName("result");
            if (resultList.getLength() > 0) {
                Node resultNode = resultList.item(0);
                if (resultNode.getNodeType() == Node.ELEMENT_NODE) {
                    result = resultNode.getTextContent().trim();
                }
            }

            // 解析 <fileid> 元素
            NodeList fileidList = root.getElementsByTagName("fileid");
            if (fileidList.getLength() > 0) {
                Node fileidNode = fileidList.item(0);
                if (fileidNode.getNodeType() == Node.ELEMENT_NODE) {
                    fileid = fileidNode.getTextContent().trim();
                }
            }

            // 解析 <errormessage> 元素
            NodeList errormessageList = root.getElementsByTagName("errormessage");
            if (errormessageList.getLength() > 0) {
                Node errormessageNode = errormessageList.item(0);
                if (errormessageNode.getNodeType() == Node.ELEMENT_NODE) {
                    errormessage = errormessageNode.getTextContent().trim();
                }
            }

        } catch (Exception e) {
            e.printStackTrace();
        }

        return new String[]{fileid, result, errormessage};
    }

    public static String parseErrorMessage(String response) {
        try {
            // 1. 解析外层JSON
            JSONObject json = JSONObject.parseObject(response);

            // 检查是否有错误信息
            boolean success = json.getBooleanValue("success");
//            if (success) {
//                return "操作成功";
//            }

            // 获取XML格式的错误信息
            String xmlData = json.getString("data");
            if (xmlData == null || xmlData.isEmpty()) {
                return json.getString("message");
            }

            // 2. 解析XML中的错误信息
            DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
            DocumentBuilder builder = factory.newDocumentBuilder();
            Document doc = builder.parse(new InputSource(new StringReader(xmlData)));

            // 获取<errormessage>节点内容
            NodeList errorNodes = doc.getElementsByTagName("errormessage");
            if (errorNodes.getLength() > 0) {
                Node errorNode = errorNodes.item(0);
                String errorMessage = errorNode.getTextContent();

                // 3. 提取关键错误信息（可选）
                // 这里可以根据具体需求进一步处理SQLException信息
                return extractKeyErrorMessage(errorMessage);
            }

            return "未知错误";
        } catch (Exception e) {
            // 解析失败时返回原始响应或错误信息
            return "解析错误信息失败: " + e.getMessage() + "\n原始响应: " + response;
        }
    }

    /**
     * 从冗长的SQLException中提取关键错误信息
     */
    private static String extractKeyErrorMessage(String fullErrorMessage) {
        if (fullErrorMessage == null) return "";

        // 提取重复键错误信息
        if (fullErrorMessage.contains("Duplicate entry")) {
            int startIdx = fullErrorMessage.indexOf("Duplicate entry");
            int endIdx = fullErrorMessage.indexOf("nested exception is", startIdx);
            if (endIdx == -1) endIdx = fullErrorMessage.length();

            return fullErrorMessage.substring(startIdx, endIdx).trim();
        }

        // 提取其他类型的关键错误（可根据需要扩展）
        return fullErrorMessage;
    }
}
